<script charset="UTF-8">
    $('#menu_list_add').click(function () {
        var _dialog = $('<div/>').dialog({
            title: '新增菜单',
            href: '${ctxPath}/menu/form',
            modal: true,
            width: 400,
            height: 300,
            cache: false,
            buttons: [{
                text: '新增',
                iconCls: 'icon-add',
                handler: function () {
                    _dialog.dialog('destroy');
                }
            }, {
                text: '取消',
                handler: function () {
                    _dialog.dialog('destroy');
                }
            }]
        });
    });
    $('#menu_list_edit').click(function () {
        var row = $('#menu_list_treeGrid').treegrid('getSelected');
        if (row) {
            var _dialog = $('<div/>').dialog({
                title: '编辑菜单',
                href: '${ctxPath}/menu/form?id=' + row.id,
                modal: true,
                width: 400,
                height: 300,
                cache: false,
                buttons: [{
                    text: '编辑',
                    iconCls: 'icon-edit',
                    handler: function () {
                        $('#menu_form_form').form('submit', {
                            url: '${ctxPath}/menu/edit',
                            onSubmit: function () {
                            },
                            success: function (result) {
                                var result = eval('(' + result + ')');
                                if (result.success) {
                                    $('#menu_list_treeGrid').treegrid('reload');
                                    $.messager.alert('提示', '编辑成功！', 'info');
                                } else {
                                    $.messager.alert('提示', '编辑失败！', 'error');
                                }
                                _dialog.dialog('destroy');
                            }
                        });
                    }
                }, {
                    text: '取消',
                    handler: function () {
                        _dialog.dialog('destroy');
                    }
                }]
            });
        }
    });
    $('#menu_list_remove').click(function () {
        var row = $('#menu_list_treeGrid').treegrid('getSelected');
        if (row) {
            $.messager.confirm('询问', '您确定要删除 [' + row.name + '] ？', function (r) {
                if (r) {
                    $.post('${ctxPath}/menu/delete/' + row.id, function (result) {
                        if (result.success) {
                            $('#menu_list_treeGrid').treegrid('reload');
                            $.messager.alert('提示', '[' + row.name + '] 删除成功！', 'info');
                        } else {
                            $.messager.alert('提示', '[' + row.name + '] 删除失败！', 'error');
                        }
                    });
                }
            });
        }
    });
</script>
<div id="menu_list_treeGridToolbar">
    <a id="menu_list_add" href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">新增</a>
    <a id="menu_list_edit" href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">编辑</a>
    <a id="menu_list_remove" href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">删除</a>
</div>
<table id="menu_list_treeGrid" class="easyui-treegrid"
       data-options="url:'${ctxPath}/menu/list',idField:'id',treeField:'name',parentField:'pid',fit:true,border:false,toolbar:'#menu_list_treeGridToolbar'">
    <thead>
    <tr>
        <th data-options="field:'id'">ID</th>
        <th data-options="field:'name'">菜单名称</th>
        <th data-options="field:'url'">访问地址</th>
        <th data-options="field:'type'
                           ,formatter:function(value,row,index){
                                if(value==0){
                                    return '菜单';
                                }else{
                                    return '按钮';
                                }
                           }">类型
        </th>
        <th data-options="field:'sort'">排序</th>
    </tr>
    </thead>
</table>